<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="分子结构存储路径" prop="mol">
        <el-input
          v-model="queryParams.mol"
          placeholder="请输入分子结构存储路径"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="导入表名" prop="sourceTable">
        <el-input
          v-model="queryParams.sourceTable"
          placeholder="请输入导入表名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="导入表行id" prop="souceId">
        <el-input
          v-model="queryParams.souceId"
          placeholder="请输入导入表行id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['output:thermoInfo:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['output:thermoInfo:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['output:thermoInfo:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['output:thermoInfo:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="thermoInfoList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="导入表行id" align="center" prop="id" />
      <el-table-column label="导入表行id" align="center" prop="reference" />
      <el-table-column label="导入表行id" align="center" prop="testmethod" />
      <el-table-column label="导入表行id" align="center" prop="cpinfo" />
      <el-table-column label="导入表行id" align="center" prop="cpError" />
      <el-table-column label="导入表行id" align="center" prop="sinfo" />
      <el-table-column label="导入表行id" align="center" prop="sError" />
      <el-table-column label="导入表行id" align="center" prop="hinfo" />
      <el-table-column label="导入表行id" align="center" prop="hError" />
      <el-table-column label="导入表行id" align="center" prop="cpT" />
      <el-table-column label="导入表行id" align="center" prop="cpParms" />
      <el-table-column label="导入表行id" align="center" prop="chemkinDat" />
      <el-table-column label="导入表行id" align="center" prop="casNo" />
      <el-table-column label="导入表行id" align="center" prop="smiles" />
      <el-table-column label="分子结构存储路径" align="center" prop="mol" />
      <el-table-column label="导入表名" align="center" prop="sourceTable" />
      <el-table-column label="导入表行id" align="center" prop="souceId" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['output:thermoInfo:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['output:thermoInfo:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改热力学数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="导入表行id" prop="reference">
          <el-input
            v-model="form.reference"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="导入表行id" prop="testmethod">
          <el-input
            v-model="form.testmethod"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="导入表行id" prop="cpinfo">
          <el-input
            v-model="form.cpinfo"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="导入表行id" prop="cpError">
          <el-input
            v-model="form.cpError"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="导入表行id" prop="sinfo">
          <el-input
            v-model="form.sinfo"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="导入表行id" prop="sError">
          <el-input
            v-model="form.sError"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="导入表行id" prop="hinfo">
          <el-input
            v-model="form.hinfo"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="导入表行id" prop="hError">
          <el-input
            v-model="form.hError"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="导入表行id" prop="cpT">
          <el-input
            v-model="form.cpT"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="导入表行id" prop="cpParms">
          <el-input
            v-model="form.cpParms"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="导入表行id" prop="chemkinDat">
          <el-input
            v-model="form.chemkinDat"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="导入表行id" prop="casNo">
          <el-input
            v-model="form.casNo"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="导入表行id" prop="smiles">
          <el-input
            v-model="form.smiles"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="分子结构存储路径" prop="mol">
          <el-input v-model="form.mol" placeholder="请输入分子结构存储路径" />
        </el-form-item>
        <el-form-item label="导入表名" prop="sourceTable">
          <el-input v-model="form.sourceTable" placeholder="请输入导入表名" />
        </el-form-item>
        <el-form-item label="导入表行id" prop="souceId">
          <el-input v-model="form.souceId" placeholder="请输入导入表行id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listThermoInfo,
  getThermoInfo,
  delThermoInfo,
  addThermoInfo,
  updateThermoInfo,
  exportThermoInfo,
} from "@/api/output/thermoInfo";

export default {
  name: "ThermoInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 热力学数据表格数据
      thermoInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        reference: null,
        testmethod: null,
        cpinfo: null,
        cpError: null,
        sinfo: null,
        sError: null,
        hinfo: null,
        hError: null,
        cpT: null,
        cpParms: null,
        chemkinDat: null,
        casNo: null,
        smiles: null,
        mol: null,
        sourceTable: null,
        souceId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sourceTable: [
          { required: true, message: "导入表名不能为空", trigger: "blur" },
        ],
        souceId: [
          { required: true, message: "导入表行id不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询热力学数据列表 */
    getList() {
      this.loading = true;
      listThermoInfo(this.queryParams).then((response) => {
        this.thermoInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        reference: null,
        testmethod: null,
        cpinfo: null,
        cpError: null,
        sinfo: null,
        sError: null,
        hinfo: null,
        hError: null,
        cpT: null,
        cpParms: null,
        chemkinDat: null,
        casNo: null,
        smiles: null,
        mol: null,
        sourceTable: null,
        souceId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加热力学数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getThermoInfo(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改热力学数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateThermoInfo(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addThermoInfo(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除热力学数据编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delThermoInfo(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有热力学数据数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportThermoInfo(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
